const app = getApp()

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    user: {
      nickName: '点击微信授权',
      src: '../../images/wechat.png'
    },
		shose: [{
			device_name: "X5进化1"
		},
		{
			device_name: "X5进化2"
		},
		{
			device_name: "X5进化3"
		}
		]
  },

  to_add_device: function(e) {
    wx.navigateTo({
			url: '../addDevice/addDevice',
    })
  },

  onLoad: function() {
    wx.setNavigationBarTitle({
      title: '我的',
    })
  },

  getUserInfo: function(e) {
		var that = this
		if (app.globalData.customer){
			wx.navigateTo({
				url: '../userInfo/userInfo',
			})
		}else{
			wx.getUserInfo({
				success: res => {
					app.globalData.customer = res.userInfo
					app.globalData.shose = that.data.shose
					that.setData({
						user: {
							nickName: res.userInfo.nickName,
							src: res.userInfo.avatarUrl
						}
					})
				}
			})
		}
		
  },

  // getopenid: function() {
  //   let that = this;
  //   const db = wx.cloud.database()
  //   wx.cloud.callFunction({
  //     name: "openid",
  //     complete: res => {
  //       console.log("openid--", res.result)
  //       db.collection('user').add({
  //         data: {
  //           signature: res.result.openid
  //         },
  //         success(res) {
  //           console.log(res)
  //         }
  //       })
  //     }
  //   })
  // }
})